using System;
using System.ComponentModel;
using App.Modelo.Interfaces;

namespace App.SolInf.Modelo
{
    public class Empresa : ICliente, INotifyPropertyChanged
    {
        private IDomicilio _domicilio;
        private IDocumento _documento;
        private string _nombreFantasia;
        private string _razonSocial;

        
        
        public virtual int Id { get; set; }
        public virtual DateTime? FechaAlta { get; set; }

        public Empresa()
        {
            FechaAlta = DateTime.Now;
        }
        [TypeConverter(typeof(StringConverter))]
        public virtual IDocumento Documento
        {
            get { return _documento ?? (_documento = new Documento()); }
            set { _documento = value; }
        }

        public virtual string RazonSocial
        {
            get
            {
                return _razonSocial;
            }
            set 
            { 
                _razonSocial = value;
                _propertyChanged("NombreFantasia");
            }
        }

        public virtual string Contacto { get; set; }

        public virtual string NombreFantasia
        {
            get
            {
                if (String.IsNullOrEmpty(_nombreFantasia))
                    return RazonSocial;
                return _nombreFantasia;
            }
            set { _nombreFantasia = value; }
        }

        [TypeConverter(typeof(StringConverter))] 
        public virtual IDomicilio Domicilio
        {
            get { return _domicilio ?? (_domicilio = new Domicilio()); }
            set { _domicilio = value; }
        }


        public virtual string Telefono1 { get; set; }

        public virtual string Telefono2 { get; set; }

        public virtual string Email { get; set; }

        public override string ToString()
        {
            return NombreFantasia;
        }

        public virtual event PropertyChangedEventHandler PropertyChanged;

        private void _propertyChanged(string property)
        {
            if( PropertyChanged != null )
                PropertyChanged (this, new PropertyChangedEventArgs(property));
        }
    }
}